package com.yong.mestock.service;

import com.alibaba.fastjson.JSON;
import com.yong.mestock.mapper.CommonMapper;
import com.yong.mestock.mapper.StockCodeListMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class StockCodeListSvc {
    @Autowired
    private StockCodeListMapper stockCodeList;

    @Autowired
    private CommonMapper commonMapper;


    @Cacheable(key="#tableName",value="StockCodeListSvc_findTableCache")
    public Object findTable(String tableName){

        List<Map<String, String>> columns = commonMapper.findColumn(tableName);
        List<Map<String, String>> stockcodelist = commonMapper.selectDataByTableName(tableName);
        HashMap<Object, Object> resultMap = new HashMap<>();
        resultMap.put("columns",columns);
        resultMap.put("data",stockcodelist);
        return resultMap;
    }

    public Object findAllTableName(){
        List<String> allTableName = commonMapper.findAllTableName();
        return allTableName;
    }

}
